using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sec_scan漏洞扫描系统.Sec_System
{
    /// <summary>
    /// 系统设置
    /// </summary>
    public class Sec_SystemConfigAll
    {
        /// <summary>
        /// 系统设置-密码设置
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string PassWordConfig(string password)
        {
            string pass = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_SystemConfigAllAPI.P1);//获取连接的方式
            SQLiteConnection dataConn = new SQLiteConnection(pass);
            try
            {
                dataConn.Open();
                string base64 = Sec_Config.Sec_Base64Code.Tobase64(Sec_Api.Sec_SystemConfigAllAPI.PassWords);//base64编码的方式，对其密码
                string sql = "UPDATE Sec_Admin SET sec_password='"+base64+"', sec_addtime='"+DateTime.Now+"'";//更新密码的方法
                SQLiteCommand command = new SQLiteCommand(sql, dataConn);
                SQLiteDataReader reader = command.ExecuteReader();
                string ExpOk = "密码更新成功！";
                Sec_Api.Sec_SystemConfigAllAPI.ExpOk = ExpOk.ToString();
            }
            catch(Exception ex)
            {
                string Exp = ex.ToString();
                Sec_Api.Sec_SystemConfigAllAPI.ExpOptions = Exp.ToString();
            }
            return password;
        }
        /// <summary>
        /// 加载系统账号
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string UserWordRefer(string password)
        {
            string pass = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_SystemConfigAllAPI.P1);//获取连接的方式
            SQLiteConnection dataConn = new SQLiteConnection(pass);
            try
            {
                dataConn.Open();
                string sql = Sec_Api.Sec_AllAPI.UserRefer(Sec_Api.Sec_SystemConfigAllAPI.P1);//加载系统账号
                SQLiteCommand command = new SQLiteCommand(sql, dataConn);
                using(SQLiteDataReader reder = command.ExecuteReader())
                {
                    while (reder.Read())
                    {
                        string user = reder["sec_user"].ToString();
                        Sec_Api.Sec_SystemConfigAllAPI.User = user.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                string Exp = ex.ToString();
                Sec_Api.Sec_SystemConfigAllAPI.ExpOptions = Exp.ToString();
            }
            return password;
        }
    }
}
